package com.inspur.security.cbb3.kms.config.security;

import com.inspur.security.cbb3.kms.utils.ServletUtil;
import com.inspur.security.cbb3.kms.enums.SystemCode;
import org.springframework.http.HttpStatus;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 权限不足处理类
 * @author lijunchang
 */
@Component("RestAuthenticationAccessDeniedHandler")
public class RestAuthenticationAccessDeniedHandler implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest httpServletRequest, HttpServletResponse response, AccessDeniedException e) throws IOException{
        //登陆状态下，权限不足执行该方法
        ServletUtil.returnException(response, SystemCode.ERR_FORBIDDEN, HttpStatus.FORBIDDEN);
    }
}
